package com.wookii.friedeggs.data

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import kotlinx.coroutines.flow.Flow

/**
 *@Author Nick.wu
 *Date 2023/9/25
 */
@Dao
interface StudentDao {
    @Insert
    suspend fun insertAll(student: List<Student>)

    @Delete
    fun delete(student: Student)

    @Query("SELECT * FROM student")
    fun getAll(): Flow<MutableList<Student>>

    @Update
    fun updateStudent(vararg student: Student)
}

@Dao
interface ExamDao {

    @Insert
    fun insert(exam: Exam): Long

    @Transaction
    @Query("SELECT * FROM exam WHERE isFinished = :isFinished ORDER BY id ASC")
    fun getStudentsByExam(isFinished: Boolean): Flow<MutableList<ExamStudent>>

    @Query("SELECT * FROM exam")
    fun getAll(): Flow<MutableList<Exam>>
//    fun updateExamById(currentExamId: Long?, text: CharSequence)
    @Update
    fun updateExam(currentExam: Exam)

}
@Dao
interface ClassDao {
    @Insert
    fun insert(classInfo: Class)

}